//
//  CycSwitchCell.m
//  Cycling
//
//  Created by cjg on 2023/3/12.
//

#import "CycSwitchCell.h"


@interface CycSwitchCell ()
@property (nonatomic , strong) UIView *shadeView;
@end

@implementation CycSwitchCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = COLOR_APP_BACKGROUND;
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
        [self setupUI];
    }
    return self;
}
- (void)setupUI{
    self.titleLB = [[UILabel alloc] init];
    self.titleLB.font = FONT_SECONDARY_TITLE;
    self.titleLB.textColor = COLOR_WHITE;
    [self.contentView addSubview:self.titleLB];
    [self.titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(MARGIN_MAX);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.height.mas_equalTo(30);
    }];
    
    self.cellsSwitch = [[CycSwitch alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
    [self.cellsSwitch setOnTintColor:COLOR_TOPIC_SELECT];
    [self.cellsSwitch setContrastColor:COLOR_OFFLINE];
    [self.cellsSwitch setTintColor:COLOR_OFFLINE];
    [self.cellsSwitch addTarget:self action:@selector(switchClick:) forControlEvents:UIControlEventValueChanged];
    [self.contentView addSubview:self.cellsSwitch];
    [self.cellsSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(60, 30));
        make.right.equalTo(self.contentView).offset(-MARGIN_MAX);
        make.centerY.mas_equalTo(self.mas_centerY);
    }];
    
    self.shadeView = [[UIView alloc] init];
    self.shadeView.backgroundColor = COLOR_SIMPLEBLACK;
    [self.contentView addSubview:self.shadeView];
    [self.shadeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.contentView).offset(0);
    }];
    self.shadeView.hidden = YES;
}

- (void)switchClick:(CycSwitch *)sender {
    if (self.block) {
        self.block(sender.on);
    }
}

-(void)setIsUserEnable:(BOOL)isUserEnable {
    _isUserEnable = isUserEnable;
    self.shadeView.hidden = isUserEnable;
    self.userInteractionEnabled = isUserEnable;
}


@end
